*****************************************************************************************************************************************************
* PROJECT: 		Exposure to the COVID-19 Stock Market Crash and its Effect on Household Expectations
* DATE: 		Nov 2020
* CONTENT: 		FIGURES
* AUTHORS: 		Tobin Hanspal, Johannes Wohlfart, Anni Weber
*****************************************************************************************************************************************************

		clear all
		set scheme lean2
		global pm = char(177)
		set more off
		gl date = c(current_date)
		graph set window fontface "cmr10"
		
		
* set cd as /Replication_files_HanspalWeberWohlfart2020/

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~						
** Figure A7
*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~		
	
use data/processed/data_1, clear 
keep if control_pure==1 |control_fincrisis==1 | control_dotcom==1 | control_black==1 

	*~ constrained
	gen h_constrained=(constrained>3)
	gen h_retired = (retired==1)

	*~ age 
	gen h_age=(age>48)
	tab hhnetinc_19 if hhnetinc19_NR==0

	*~ net income 
	gen h_netinc=(hhnetinc_19>4)
	gen h_netinc_alt=(hhnetinc_19>3)
	replace h_netinc=. if hhnetinc19_NR==1

	*~ other financial wealth 
	drop h_ofinwealth_lvl 
	sum ofinwealth_lvl, d
	gen h_ofinwealth_lvl=(ofinwealth_lvl>0)

	*~ net wealth 
	sum netwealth_Jan20, d
	gen h_netwealth=(netwealth_Jan20<r(p50))

	*~ recovery duration own net income  
	replace recov_owninc_duration=0 if recov_owninc_duration<0
	sum recov_owninc_duration  , d
	replace recov_owninc_duration=20 if never_owninc==1
	gen h_recovinc=(recov_owninc_duration>0)
	gen h_never_owninc = (never_owninc==1)

	*~ recovery duration own net wealth 
	sum recov_hhwealth_duration, d
	replace recov_hhwealth_duration=20 if never_ownwealth==1
	sum recov_hhwealth_duration, d
	gen h_recovwealth=(recov_hhwealth_duration>=r(p50))
	
	*~ demo
	gen h_male = male
	gen h_bach = atleast_bachelor 
	gen h_empl_ft =  empl_ft
	tab svydate, gen(svydate_)
			
global controls 		ln_hhnetinc  ///
						ln_ofinwealth_lvl ln_retirewealth_lvl  ///
						ln_realestate_lvl realestJan20_NR		///
						ln_debt_lvl  debtJan20_NR ///
						stockinvestor riskshare_finwealth_Jan201 stockexperience ///
						 age_25_34 age_35_44 age_45_54 age_55_64 age_65 male married separated_divorced widowed ///	
						highschool some_college_associate_degree atleast_bachelor  ///
						mainearner_alone z_constrained self_empl retired unempl empl_other ///
						republican other_party NR_party  ///
						z_decisionmaker ///
						midwest northeast south ///
						svydate_2 svydate_3 svydate_4 svydate_5 svydate_6 svydate_7 svydate_8 ///
						control_fincrisis control_dotcom control_black
									
			
** WEALTH:
foreach x in age netinc_alt ofinwealth_lvl 	never_owninc constrained retired  {

		reg del_spend20_usd_tr02alt /// 
									delretir_USD_tr02alt ///
									delofin_USD_tr02alt ///
									delhhnetinc_USD_tr02alt_qtr ///
									$controls 		if h_`x'==0 ///
									, robust
									
													
				margins, dydx(delretir_USD_tr02alt) post
				est store `x'_rw_0	
				
		reg del_spend20_usd_tr02alt /// 
									delretir_USD_tr02alt ///
									delofin_USD_tr02alt ///
									delhhnetinc_USD_tr02alt_qtr ///
									$controls 		if h_`x'==0 ///
									, robust
									
													
				margins, dydx(delofin_USD_tr02alt) post
				est store `x'_ow_0		
				
									
		reg del_spend20_usd_tr02alt /// 
									delretir_USD_tr02alt ///
									delofin_USD_tr02alt ///
									delhhnetinc_USD_tr02alt_qtr ///
									$controls 		if h_`x'==1 ///
									, robust				
									
				margins, dydx( delretir_USD_tr02alt) post
				est store `x'_rw_1				
		
		reg del_spend20_usd_tr02alt /// 
									delretir_USD_tr02alt ///
									delofin_USD_tr02alt ///
									delhhnetinc_USD_tr02alt_qtr ///
									$controls 		if h_`x'==1 ///
									, robust				
									
				margins, dydx(delofin_USD_tr02alt ) post
				est store `x'_ow_1		
}				
			
	* age	
		coefplot  	///
					(age_rw_0, label(Below med. age)  )		 ///
					(age_rw_1, label(Above med. age))		 ///
					, 	coeflabel(delretir_USD_tr02alt = "Retirement wealth", labsize(medium))	recast(bar) vert  barwidth(0.3) ///
					vert ylabel(-.1(.05).1, nogrid) ciopts(recast(rcap)) citop  level(90) ysize(1) xsize(1) ///
					legend(size(medsmall) symxsize(5) bmargin(tiny) yoffset(0) pos(6) ring(1) cols(1))  saving(Figures/coeftemp1.gph, replace)
					
		coefplot  	///
					(age_ow_0, label(Below med. age)  )		 ///
					(age_ow_1, label(Above med. age))		 ///
					, 	coeflabel(delofin_USD_tr02alt = "Other fin. wealth", labsize(medium))	recast(bar) vert  barwidth(0.3) ///
					vert ylabel(-.1(.05).1, nogrid labcolor(white) tlcolor(white) )  yscale(noline axis(1)) ciopts(recast(rcap)) citop  level(90) ysize(1) xsize(1) ///
					legend(size(medsmall) symxsize(5) bmargin(tiny) yoffset(0) pos(6) ring(1) cols(1)) saving(Figures/coeftemp2.gph, replace)	
					
		grc1leg2 	Figures/coeftemp1.gph ///
					Figures/coeftemp2.gph ///
					, cols(2) rows(1) ysize(1) xsize(1) ///
					ring(1) pos(6) l1title("", size(small)) ///
					legendfrom(Figures/coeftemp1.gph) note("Age", pos(12) size(medium)) ///
					saving(Figures/coef_1.gph, replace) imargin(-10 0 0 0) ycommon xcommon
			
		* netinc	
		coefplot  	///
					(netinc_alt_rw_0, label(Below med. net income)  )		 ///
					(netinc_alt_rw_1, label(Above med. net income))		 ///
					, 	coeflabel(delretir_USD_tr02alt = "Retirement wealth", labsize(medsmall))	recast(bar) vert  barwidth(0.3) ///
					vert ylabel(-.1(.05).1, nogrid) ciopts(recast(rcap)) citop  level(90) ysize(1) xsize(1) ///
					legend(size(medsmall) symxsize(5) bmargin(tiny) yoffset(0) pos(6) ring(1) cols(1)) saving(Figures/coeftemp1.gph, replace)
					
		coefplot  	///
					(netinc_alt_ow_0, label(Below med. net income)  )		 ///
					(netinc_alt_ow_1, label(Above med. net income))		 ///
					, 	coeflabel(delofin_USD_tr02alt = "Other fin. wealth", labsize(medium))	recast(bar) vert  barwidth(0.3) ///
					vert ylabel(-.1(.05).1, nogrid labcolor(white) tlcolor(white) )  yscale(noline axis(1)) ciopts(recast(rcap)) citop  level(90) ysize(1) xsize(1) ///
					legend(size(medsmall) symxsize(5) bmargin(tiny) yoffset(0) pos(6) ring(1) cols(1))	saving(Figures/coeftemp2.gph, replace)	
					
		grc1leg2 	Figures/coeftemp1.gph ///
					Figures/coeftemp2.gph ///
					, cols(2) rows(1) ysize(1) xsize(1) ///
					ring(1) pos(6) l1title("", size(small)) ///
					legendfrom(Figures/coeftemp1.gph) note("Net income", pos(12) size(medium)) ///
					saving(Figures/coef_2.gph, replace)	imargin(-10 0 0 0) ycommon xcommon
					
							
		* ofinwealth_lvl	
		coefplot  	///
					(ofinwealth_lvl_rw_0, label(Zero other fin. wealth)  )		 ///
					(ofinwealth_lvl_rw_1, label(Positive other fin. wealth))		 ///
					, 	coeflabel(delretir_USD_tr02alt = "Retirement wealth", labsize(medsmall))	recast(bar) vert  barwidth(0.3) ///
					vert ylabel(-.15(.075).15, nogrid) ciopts(recast(rcap)) citop  level(90)  ysize(1) xsize(1) ///
					legend(size(medsmall) symxsize(5) bmargin(tiny) yoffset(0) pos(6) ring(1) cols(1))  saving(Figures/coeftemp1.gph, replace)
					
		coefplot  	///
					(ofinwealth_lvl_ow_0, label(Zero other fin. wealth)  )		 ///
					(ofinwealth_lvl_ow_1, label(Positive other fin. wealth))		 ///
					, 	coeflabel(delofin_USD_tr02alt = "Other fin. wealth", labsize(medium))	recast(bar) vert  barwidth(0.3) ///
					vert ylabel(-.15(.075).15, nogrid labcolor(white) tlcolor(white) )  yscale(noline axis(1)) ciopts(recast(rcap)) citop  level(90) ysize(1) xsize(1) ///
					legend(size(medsmall) symxsize(5) bmargin(tiny) yoffset(0) pos(6) ring(1) cols(1))saving(Figures/coeftemp2.gph, replace)	
					
		grc1leg2 	Figures/coeftemp1.gph ///
					Figures/coeftemp2.gph ///
					, cols(2) rows(1) ysize(1) xsize(1) ///
					ring(1) pos(6) l1title("", size(small)) ///
					legendfrom(Figures/coeftemp1.gph) note("Other financial wealth", pos(12) size(medium)) ///
					saving(Figures/coef_3.gph, replace) imargin(-10 0 0 0)	ycommon xcommon
													
		*never_owninc	
				coefplot  	///
					(never_owninc_rw_0, label(Income will recover)  )		 ///
					(never_owninc_rw_1, label(Income will never recover))		 ///
					, 	coeflabel(delretir_USD_tr02alt = "Retirement wealth", labsize(medsmall))	recast(bar) vert  barwidth(0.3) ///
					vert ylabel(-.1(.05).1, nogrid) ciopts(recast(rcap)) citop  level(90)  ysize(1) xsize(1) ///
					legend(size(medsmall) symxsize(5) bmargin(tiny) yoffset(0) pos(6) ring(1) cols(1))  saving(Figures/coeftemp1.gph, replace)
					
		coefplot  	///
					(never_owninc_ow_0, label(Income will recover)  )		 ///
					(never_owninc_ow_1, label(Income will never recover))		 ///
					, 	coeflabel(delofin_USD_tr02alt = "Other fin. wealth", labsize(medium))	recast(bar) vert  barwidth(0.3) ///
					vert ylabel(-.1(.05).1, nogrid labcolor(white) tlcolor(white) )  yscale(noline axis(1)) ciopts(recast(rcap)) citop  level(90) ysize(1) xsize(1) ///
					legend(size(medsmall)  pos(6) ring(1) cols(1))	saving(Figures/coeftemp2.gph, replace)	
					
		grc1leg2 	Figures/coeftemp1.gph ///
					Figures/coeftemp2.gph ///
					, cols(2) rows(1) ysize(1) xsize(1) ///
					ring(1) pos(6) l1title("", size(small)) ///
					legendfrom(Figures/coeftemp1.gph) span    note("Income will never recover", pos(12) size(medium)) ///
					saving(Figures/coef_4.gph, replace)  imargin(-10 0 0 0)	ycommon xcommon
			
			
		*constrained	
				coefplot  	///
					(constrained_rw_0, label(Unconstrained)  )		 ///
					(constrained_rw_1, label(Constrained))		 ///
					, 	coeflabel(delretir_USD_tr02alt = "Retirement wealth", labsize(medsmall))	recast(bar) vert  barwidth(0.3) ///
					vert ylabel(-.2(.1).2, nogrid) ciopts(recast(rcap)) citop  level(90)  ysize(1) xsize(1) ///
					legend(size(medsmall) symxsize(5) bmargin(tiny) yoffset(0) pos(6) ring(1) cols(1))  saving(Figures/coeftemp1.gph, replace)
					
		coefplot  	///
					(constrained_ow_0, label(Unconstrained)  )		 ///
					(constrained_ow_1, label(Constrained))		 ///
					, 	coeflabel(delofin_USD_tr02alt = "Other fin. wealth", labsize(medium))	recast(bar) vert  barwidth(0.3) ///
					vert ylabel(-.2(.1).2, nogrid labcolor(white) tlcolor(white) )  yscale(noline axis(1))  ciopts(recast(rcap)) citop  level(90) ysize(1) xsize(1) ///
					legend(size(medsmall)  pos(6) ring(1) cols(1))	saving(Figures/coeftemp2.gph, replace)	
					
		grc1leg2 	Figures/coeftemp1.gph ///
					Figures/coeftemp2.gph ///
					, cols(2) rows(1) ysize(1) xsize(1) ///
					ring(1) pos(6) l1title("", size(small)) ///
					legendfrom(Figures/coeftemp1.gph) span    note("Constrained", pos(12) size(medium)) ///
					saving(Figures/coef_5.gph, replace)  imargin(-10 0 0 0)	ycommon xcommon
			
		
		*retired	
				coefplot  	///
					(retired_rw_0, label(All other)  )		 ///
					(retired_rw_1, label(Retired))		 ///
					, 	coeflabel(delretir_USD_tr02alt = "Retirement wealth", labsize(medsmall))	recast(bar) vert  barwidth(0.3) ///
					vert ylabel(-.1(.05).1, nogrid) ciopts(recast(rcap)) citop  level(90)  ysize(1) xsize(1) ///
					legend(size(medsmall) symxsize(5) bmargin(tiny) yoffset(0) pos(6) ring(1) cols(1))  saving(Figures/coeftemp1.gph, replace)
					
		coefplot  	///
					(retired_ow_0, label(All other)  )		 ///
					(retired_ow_1, label(Retired))		 ///
					, 	coeflabel(delofin_USD_tr02alt = "Other fin. wealth", labsize(medium))	recast(bar) vert  barwidth(0.3) ///
					vert ylabel(-.1(.05).1, nogrid labcolor(white) tlcolor(white) )  yscale(noline axis(1))  ciopts(recast(rcap)) citop  level(90) ysize(1) xsize(1) ///
					legend(size(medsmall)  pos(6) ring(1) cols(1))	saving(Figures/coeftemp2.gph, replace)	
					
		grc1leg2 	Figures/coeftemp1.gph ///
					Figures/coeftemp2.gph ///
					, cols(2) rows(1) ysize(1) xsize(1) ///
					ring(1) pos(6) l1title("", size(small)) ///
					legendfrom(Figures/coeftemp1.gph) span    note("Retired", pos(12) size(medium)) ///
					saving(Figures/coef_6.gph, replace)	  imargin(-10 0 0 0) ycommon xcommon
			
					
		graph combine 	Figures/coef_1.gph ///
						Figures/coef_2.gph ///
						Figures/coef_3.gph ///
						Figures/coef_4.gph ///
						Figures/coef_5.gph ///
						Figures/coef_6.gph ///
						, cols(3) rows(2) ysize(3) xsize(5) ///
						l1title("Expected spending growth ($)", size(small)) ///
						iscale(.65) imargin(large) graphregion(color(white)) 

						
		graph export Figures/FigureA7.pdf, as(pdf) fontface("cmr10") replace
		graph export Figures/FigureA7.png, width(1600) replace	 	
			
forvalues x = 1/6 {
		capture erase Figures/coef_`x'.gph
		capture erase Figures/coeftemp`x'.gph		
}	
